package com.audi.demo.action;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.stereotype.Controller;

import com.audi.core.common.BaseAction;
import com.audi.core.common.Page;

/**
 * action 类
 * 
 * @author hujh
 * 
 */

@Controller
@ParentPackage("demo")
@Namespace("/demo")
public class DemoAction extends BaseAction {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1663402493568576216L;

	
	private Page<String> page;
	
	private Integer id = 1;
	
	
	@Action(value = "list", results = {
			@Result(name = "error", location = "www.baidu.com", type = "redirect"),
			@Result(name = "success", location = "/WEB-INF/jsp/demo/index.jsp") })
	public String list() {
		System.out.println(".....");
		HttpServletRequest request = ServletActionContext.getRequest();  
		HttpSession session = request.getSession();  
		ServletContext application = session.getServletContext(); 
		System.out.println(application.getAttribute("test124"));
		System.out.println(application.getAttribute("test123"));
		//userInfoDemoService.getAll().size();
		//System.out.println(UserInfoDemoServiceImpl.getList().size());
		
		
		page = new Page(2,20);
		page.setAutoCount(true);
		page.setTotalCount(1545);
		page.end();
		
		/*List<UserInfoDemo> list = new ArrayList<UserInfoDemo>();
		
		for(int i=0;i<10;i++){
			UserInfoDemo demo = new UserInfoDemo(i+100, "name:"+i);
			list.add(demo);
		}*/
		//page.setResult(list);
		
		System.out.println("page....");
		
		return "success";
	}
	
	@Action(value = "list1", results = {
			@Result(name = "error", location = "www.baidu.com", type = "redirect" ),
			@Result(name = "success", type="redirectAction", location = "list", params={"id","%{id}"})
		}
	)
	public String list1(){
		System.out.println("list1...");
		page = new Page(2,20);
		page.setAutoCount(true);
		page.setTotalCount(1545);
		page.end();
		
		System.out.println("page....");
		return "success";
	}
	

	


	public Integer getId() {
		return id;
	}


	public void setId(Integer id) {
		this.id = id;
	}

    public Page<String> getPage() {
        return page;
    }

    public void setPage(Page<String> page) {
        this.page = page;
    }

	

	
	
}
